// 医院服务的api文件
import requestInstance from './request';
const http = requestInstance({
  baseURL: 'https://njrsxxzx.cn/njrs/search/api/'
});
// 医院服务api
export function hospitalApi(data) {
  return http.request({
    url: 'healthCommissionQuery',
    method: 'POST',
    data: data
  })
}
// 提交预约信息
export function createReservation(data) {
  return http.request({
    url: 'createReservation',
    method: 'POST',
    data: data
  })
}
// 取消预约
export function cancelReservation(data) {
  return http.request({
    url: 'cancelReservation',
    method: 'POST',
    data: data
  })
}
// 创建用户
export function createPatient(data) {
  return http.request({
    url: 'createPatient',
    method: 'POST',
    data: data
  })
}
// 查询卫健委平台的用户信息 如果查到则通过 查不到则跳转到注册页
export function checkUserIsExist(data) {
  wx.showLoading({
    title: '获取用户信息...',
  })
  return new Promise((resolve, reject) => {
    hospitalApi({
      method: 'getPatientByIdnum',
      data: JSON.stringify({
        idnum: wx.getStorageSync('userInfo').idNumber
      })
    }).then(res => {
      wx.hideLoading()
      if (res.data.SUCCESSFUL == 1) {
        resolve()
      } else {
        wx.showModal({
          title: '提示',
          content: '用户不存在，是否前往注册？',
          success(res) {
            if (res.confirm) {
              wx.navigateTo({
                url: `/pages/medical/register/index`
              })
            } else if (res.cancel) {
              wx.navigateBack()
            }
          }
        })
        reject()
      }
    })
  })
}